home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 399_01 / mined.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  13.4 KB  |  491 lines

  1. /*  ====================================================================  *
  2.  *                Mined.h                      *
  3.  *  ====================================================================  */
  4.  
  5. #ifndef minedH
  6. #define minedH
  7.  
  8. #ifdef __MSDOS__
  9. #undef unix    /* needed for djgcc? */
  10. #define msdos
  11. #define pc
  12. # ifndef __TURBOC__
  13. # define __GCC__
  14. # undef msdos    /* in this queer case, a more specific distinction */
  15. # define unix    /* has to be made everywhere according to the 'pc' flag */
  16. # endif
  17. #endif
  18.  
  19. #ifdef msdos
  20. /* With Turbo-C, compile with memory model >= Compact */
  21. /* #define conio doesn't work with current combined positioning/output method */
  22. extern far * getenv ();
  23. extern far * getcwd ();
  24. extern void setdisk ();
  25. #  include <stdio.h>
  26. #  undef putchar
  27. #  include <fcntl.h>
  28. #  define FUNcmd    '\000'
  29. extern void sleep ();
  30. extern void delay ();
  31. extern void exit ();
  32. #endif
  33.  
  34. #ifdef vms
  35. #  include <unixio.h>
  36. #  include <file.h>    /* for the O_... attributes to open () */
  37. #  include <unixlib.h>
  38. #  undef putchar
  39. #  undef FALSE
  40. #  undef TRUE
  41. #  define CURSES
  42. #  define FUNcmd    '\200'
  43. #endif
  44.  
  45. #ifdef unix
  46.  
  47. /*#include <stdlib.h> */
  48. #  include <stdio.h>
  49. #  include <string.h>
  50. #  include <fcntl.h>
  51. #  include <unistd.h>
  52. #  undef putchar
  53. #  undef NULL
  54. #  undef EOF
  55. #  define FUNcmd    '\200'
  56.  
  57. #  ifndef sysV
  58.    extern char * getwd ();
  59. #  define getcwd(dirbuf, buflen)    getwd (dirbuf)
  60. #  else
  61.    extern char * getcwd ();
  62. #  endif
  63.  
  64. extern void exit ();
  65. extern char * getenv ();
  66. extern int printf ();
  67. extern int vfork ();
  68. #ifdef __GCC__
  69. extern int wait ();
  70. #else
  71. extern pid_t wait ();
  72. #endif
  73. extern int select ();
  74. extern unsigned int sleep ();
  75. extern unsigned int usleep ();
  76.  
  77. #endif /* unix */
  78.  
  79.  
  80. typedef unsigned char uchar;
  81.  
  82. /*------------------------------------------------------------------------*/
  83.  
  84. extern void raw_mode ();
  85. extern void clear_screen ();
  86. extern void clear_eol ();
  87. extern void scroll_forward ();
  88. extern void scroll_reverse ();
  89. extern void add_line (/* y */);
  90. extern void delete_line (/* y */);
  91. extern void move_cursor (/* x, y */);
  92. extern void reverse_on ();
  93. extern void reverse_off ();
  94. extern void start_screen_mode ();
  95. extern void end_screen_mode ();
  96. extern void get_term ();
  97. extern void getwinsize ();
  98.  
  99. #ifdef msdos
  100. extern void set_video_lines ();
  101. extern void set_textmode_height ();
  102. extern void switch_textmode_height ();
  103. extern void set_grafmode_height ();
  104. extern void set_fontbank ();
  105. extern void set_screen_mode ();
  106. extern void resize_screen ();
  107. #endif
  108.  
  109. extern int inputreadyafter ();
  110. extern int readchar ();
  111. extern int _readchar ();
  112. extern int __readchar ();
  113.  
  114. extern int find_y_w_o_RD ();
  115. extern int scratch_file ();
  116. extern void suspendmyself ();
  117. extern void catch_signals ();
  118. extern int char_ready_within ();
  119. extern int get_number ();
  120. extern void display ();
  121. extern void reset ();
  122. extern void move_y ();
  123. extern void move_to ();
  124. extern void set_cursor_xy ();
  125. extern void put_line ();
  126. extern void move_address ();
  127. extern int length_of ();
  128. extern int text_length_of ();
  129. extern int insert ();
  130. extern void copy_string ();
  131. extern int get_file ();
  132. extern int get_line ();
  133. extern void bad_write ();
  134. extern void file_status ();
  135. extern int find_x ();
  136. extern void RDwin ();
  137. extern void RD_y ();
  138. extern void panicio ();
  139. extern int panicwrite ();
  140. extern int wrt_text ();
  141. extern void set_font_height ();
  142. extern void changetocode ();
  143.  
  144. extern uchar grave ();
  145. extern uchar circumflex ();
  146. extern uchar acute ();
  147. extern uchar diaeresis ();
  148. extern uchar tilde ();
  149. extern uchar angstrom ();
  150.  
  151. /* aux: */
  152. extern void delete_yank_file ();
  153. extern void rd_bottom_line ();
  154. extern void clear_wholeline ();
  155. extern void clear_lastline ();
  156. extern void (* keyproc) ();
  157. extern void catch_interrupt ();
  158. extern int make_number ();
  159.  
  160. /* from system: */
  161. extern int write ();
  162. extern int read ();
  163. extern int access ();
  164. extern int open ();
  165. extern int close ();
  166. extern int creat ();
  167. extern int chdir ();
  168. extern int system ();
  169. extern int strcmp ();
  170. extern int isatty ();
  171.  
  172. /*------------------------------------------------------------------------*/
  173.  
  174. /*
  175.  * Convert cnt to nearest tab position
  176.  */
  177. #define tab(cnt)        (((cnt) + 8) & ~07)
  178. #define is_tab(c)        ((c) == '\t')
  179. /*
  180.  * Word definitions
  181.  */
  182. #define white_space(c)    ((c) == ' ' || (c) == '\t')
  183. #define alpha(c)    ((c) != ' ' && (c) != '\t' && (c) != '\n')
  184.  
  185. /* Set cursor at coordinates x, y */
  186. #define set_cursor(nx, ny)    move_cursor(nx, ny)
  187.  
  188. /* Screen size and display definitions. Coordinates start at 0, 0 */
  189. #ifdef pc
  190. #  define maxYMAX        64
  191. #  define maxXMAX        132
  192. #else
  193. #  define maxYMAX        126    /* 73 */
  194. #  define maxXMAX        279    /* 163 */
  195. #endif
  196.  
  197. extern short YMAX;
  198. extern short XMAX;
  199. #define SCREENMAX    (YMAX - 1)    /* last line displayed (first is 0) */
  200. #define XBREAK        (XMAX)    /* Shift line display at this column */
  201. #define SHIFT_SIZE    (tab (XMAX / 4 + 1))    /* Number of chars to shift */
  202. #define maxLINE_LEN    (maxXMAX + 1)    /* max screen line length */
  203. #define screen_BUFL    (maxXMAX * maxYMAX)    /* Size of I/O buffering */
  204.  
  205. #define MAX_CHARS    1024        /* max chars on one line of text */
  206.         /* LINE_START must be rounded up to the lowest SHIFT_SIZE */
  207. #define LINE_START    (((-MAX_CHARS - 1) / SHIFT_SIZE) * SHIFT_SIZE \
  208.                      - SHIFT_SIZE)
  209. #define LINE_END    (MAX_CHARS + 1)    /* Highest x-coordinate for line */
  210.  
  211. #define BLOCK_SIZE    1024
  212.  
  213. /* Return values of functions */
  214. #define ERRORS        -1
  215. #define NO_LINE        (ERRORS - 1)    /* Must be < 0 */
  216. #define FINE         (ERRORS + 1)
  217. #define NO_INPUT    (ERRORS + 2)
  218.  
  219. #define STD_IN        0        /* Input file # */
  220. #define STD_OUT         1        /* Terminal output file # */
  221. #define STD_ERR        2
  222.  
  223. #define REPORT    1        /* Report change of lines on # lines */
  224.  
  225. #ifndef pc
  226. # define O_BINARY 0
  227. #endif
  228.  
  229. /*
  230.  * Common enum type for all flags used in mined.
  231.  */
  232. typedef enum {
  233. /* General flags */
  234.   FALSE,
  235.   TRUE,
  236.   OFF,
  237.   ON,
  238. /* yank_status and other */
  239.   NOT_VALID,
  240.   VALID,
  241.  
  242. /* Expression flags */
  243.   FORWARD,
  244.   REVERSE,
  245.  
  246. /* Yank flags */
  247.   SMALLER,
  248.   BIGGER,
  249.   SAME,
  250. /*  EMPTY, */
  251.   NO_DELETE,
  252.   DELETE,
  253.   READ,
  254.   WRITE
  255. } FLAG;
  256.  
  257. /*
  258.  * The Line structure. Each line entry contains a pointer to the next line,
  259.  * a pointer to the previous line, a pointer to the text and an unsigned char
  260.  * telling at which offset of the line printing should start (usually 0).
  261.  */
  262. struct Line {
  263.   struct Line * next;
  264.   struct Line * prev;
  265.   char * text;
  266.   unsigned char shift_count;
  267. };
  268.  
  269. typedef struct Line LINE;
  270.  
  271. /* Dummy line indicator */
  272. #define DUMMY        0x80
  273. #define DUMMY_MASK    0x7F
  274.  
  275. /* Expression definitions */
  276. #define NO_MATCH    0
  277. #define MATCH        1
  278. #define REG_ERROR    2
  279.  
  280. #define BEGIN_LINE    (2 * REG_ERROR)
  281. #define END_LINE    (2 * BEGIN_LINE)
  282.  
  283. /*
  284.  * For casting functions with int/void results
  285.  */
  286. typedef void (* voidfunc) ();
  287. typedef uchar (* charfunc) ();
  288. typedef int (* intfunc) ();
  289.  
  290. /*
  291.  * Determine multi-character prefix bytes (Chinese)
  292.  */
  293. #define multichar(c)    ((uchar) c > '\177')
  294. extern int inmultichar ();
  295.  
  296. /*
  297.  * The regex structure. Status can be any of 0, BEGIN_LINE or REG_ERROR. In
  298.  * the last case, the result.err_mess field is assigned. Start_ptr and end_ptr
  299.  * point to the match found. For more details see the documentation file.
  300.  */
  301. struct regex {
  302.   union {
  303.       char * err_mess;
  304.       int * expression;
  305.   } result;
  306.   char status;
  307.   char * start_ptr;
  308.   char * end_ptr;
  309. };
  310.  
  311. typedef struct regex REGEX;
  312.  
  313. /* NULL definitions */
  314. #define NIL_PTR        ((char *) 0)
  315. #define NIL_LINE    ((LINE *) 0)
  316. #define NIL_REG        ((REGEX *) 0)
  317. #define NIL_INT        ((int *) 0)
  318.  
  319. /*
  320.  * Forward declarations
  321.  */
  322. extern int total_lines;        /* Number of lines in file */
  323. extern long total_chars;    /* Number of characters in file */
  324. extern LINE * header;        /* Head of line list */
  325. extern LINE * tail;        /* Last line in line list */
  326. extern LINE * top_line;        /* First line of screen */
  327. extern LINE * bot_line;        /* Last line of screen */
  328. extern LINE * cur_line;        /* Current line in use */
  329. extern char * cur_text;        /* Pointer to char on current line in use */
  330. extern int last_y;        /* Last y of screen, usually SCREENMAX */
  331.  
  332. extern int x, y;        /* x, y coordinates on screen */
  333. extern FLAG modified;        /* Set when file is modified */
  334. extern FLAG viewonly;        /* Set when view only mode is selected */
  335. extern FLAG quit;        /* Set when quit character is typed */
  336. extern FLAG intr_char;        /* Set when intr character is typed */
  337. extern FLAG winchg;        /* Set when the window size changes */
  338. extern FLAG waitingforinput;    /* Set while waiting for the next command key */
  339. extern FLAG isscreenmode;    /* Set when screen mode is on */
  340. extern int out_count;        /* Index in output buffer */
  341. extern char text_buffer [MAX_CHARS];    /* Buffer for modifying text */
  342. extern int input_fd;        /* File descriptors for terminal dialog */
  343. extern int output_fd;
  344. extern char SHIFT_MARK;
  345. extern int fprot;        /* To be used for file creatings */
  346. extern int bufprot;        /* To be used for paste buffer file */
  347.  
  348. extern char yank_file [];    /* Temp. file for buffer */
  349. extern char yankie_file [];    /* Temp. file for inter-window buffer */
  350. extern char panic_file [];    /* file for panic-write-back */
  351. extern FLAG yank_status;    /* Status of yank_file */
  352. extern long chars_saved;    /* # of chars saved in buffer */
  353.  
  354. extern int hop_flag;        /* set to 2 by HOP key function */
  355. extern FLAG insert_mode;    /* insert or overwrite */
  356. extern uchar control_prefix;    /* ^V/^P character to prefix control chars */
  357. extern FLAG Chinese;        /* set if two-byte characters are enabled */
  358. extern FLAG loading;        /* Loading a file? Init TRUE for error handling */
  359. extern char screen [];        /* I/O buffer for "writes" and "reads" */
  360. extern FLAG proportional;    /* Enable support for proportional fonts? */
  361. extern FLAG controlQS;        /* must respect ^Q/^S handshake ? */
  362. extern int display_delay;    /* delay between display lines */
  363. extern char TABchar;        /* Char to be shown in place of tab chars */
  364. extern char SHIFT_BEG;        /* Char indicating that line continues left */
  365. extern char RET_MARK;        /* Char indicating end of line */
  366. extern char RET_BLANK;        /* Char to fill the end of line with */
  367. extern char RET_BLANK2;        /* Char to fill last position of line with */
  368. extern char TABdefault;        /* Char displayed instead of TABs */
  369. extern char SHIFT_MARK;        /* Char indicating that line continues */
  370. extern uchar ring;        /* Ring accent character */
  371. extern FLAG rpipe;        /* Set if file should be read from stdin */
  372. extern FLAG stat_visible;    /* Set if status_line is visible */
  373.  
  374. extern void (* key_map [256]) ();
  375. extern void (* ws_key_map [32]) ();
  376. extern void (* pc_key_map [256]) ();
  377.  
  378. extern FLAG can_scroll_reverse, can_add_line, can_delete_line, can_clear_eol;
  379. extern FLAG page_scroll;    /* use scroll for page up/down */
  380. extern FLAG page_stay;        /* stay at edge of page after page up/down */
  381. extern FLAG cansuspendmyself;
  382. extern char * get_l_err1;
  383. extern char * get_l_err2;
  384. extern char * serror ();
  385. extern char * serrorof ();
  386. extern int geterrno ();
  387.  
  388. extern LINE * proceed ();
  389. extern LINE * match ();
  390. extern LINE * line_insert ();
  391. extern char * num_out ();
  392. extern int get_digits ();
  393. extern char * basename ();
  394. extern uchar promptyn ();
  395. extern FLAG checkoverwrite ();
  396. extern void delete_file ();
  397. extern char * unnull ();
  398.  
  399. #define putchar(c)    __putchar (c)
  400. extern void __putchar (); /* do not use _putchar! it may conflict with curses */
  401. extern int writechar ();
  402. extern int writestring ();
  403. extern int flush_buffer ();
  404. extern void putstring ();
  405. extern void flush ();
  406. extern void panic ();
  407. extern char * alloc ();
  408. extern void free_space ();
  409. extern LINE * alloc_header ();
  410. extern void free_header ();
  411.  
  412. /* The main editing functions */
  413.  
  414. extern void MUP (), MDN (), MLF (), MRT (), MNW (), MPW ();
  415. extern void SD (), SU (), PD (), PU (), BFILE (), EFILE ();
  416. extern void BLINE (), ELINE (), HIGH (), LOW ();
  417. extern void S (), SNL (), LIB (), DPC (), DCC (), DLN (), DNW (), DPW ();
  418. extern void CTRl (), DLINE (), TOGINS (), ctrlQ (), ctrlK (), ctrlO ();
  419. extern void JUS ();
  420. extern void QUED (), WT (), WTU (), EDIT (), RD (), I (), FS ();
  421. extern void EXED (), VIEW (), GOTO (), GOMA (), REPT (), HELP ();
  422. extern void SFW (), SRV (), RS (), LR (), GR (), REPL ();
  423. extern void MARK (), YA (), DT (), PT (), WB (), INSFILE ();
  424. extern void MARKn (), GOMAn ();
  425. extern void HOP (), CANCEL (), ESCAPE (), BAD (), FUNKEY (), DIRECT ();
  426. extern void CHDI (), PBUF (), CMD (), SH (), SUSP ();
  427. extern void LNCI (), LNSW ();
  428.  
  429. /*
  430.  * String functions
  431.  */
  432. #define streq(s1, s2)        (strcmp (s1, s2) == 0)
  433. #define strisprefix(s1, s2)    (strncmp (s2, s1, strlen (s1)) == 0)
  434.  
  435. /*
  436.  * Empty output buffer
  437.  */
  438. #define clear_buffer()        (out_count = 0)
  439.  
  440. /*
  441.  * Ring bell on terminal
  442.  */
  443. #define ring_bell()        putchar ('\07')
  444.  
  445. /*
  446.  * Print line on terminal at offset 0 and clear tail of line
  447.  */
  448. #define line_print(line)    put_line (line, 0, TRUE, FALSE)
  449.  
  450. /*
  451.  * Functions handling status_line. ON means in reverse video.
  452.  */
  453. extern int bottom_line ();
  454. #define status_msg(str)        status_line (str, NIL_PTR)
  455. #define status_line(str1, str2)        \
  456.     (void) bottom_line (ON, (str1), (str2), NIL_PTR, FALSE)
  457. #define status_beg(str)            \
  458.     (void) bottom_line (ON, (str), NIL_PTR, NIL_PTR, TRUE)
  459. #define error(str1, str2)        \
  460.     (void) bottom_line (ON, (str1), (str2), NIL_PTR, FALSE)
  461. #define clear_status()            \
  462.     (void) bottom_line (OFF, NIL_PTR, NIL_PTR, NIL_PTR, FALSE)
  463. #define get_string(str1, str2, fl)    \
  464.     bottom_line (ON, (str1), NIL_PTR, (str2), fl)
  465.  
  466. /*
  467.  * Print info about current file and buffer.
  468.  */
  469. #define fstatus(mess, cnt)    \
  470.     file_status ((mess), (cnt), file_name, total_lines, TRUE, writable, modified, viewonly)
  471.  
  472. /*
  473.  * Build formatted string.
  474.  * If this definition is left out, a routine will be defined in mined1.c.
  475.  */
  476. #define build_string sprintf /**/
  477.  
  478. /*
  479.  * Get real shift value.
  480.  */
  481. #define get_shift(cnt)        ((cnt) & DUMMY_MASK)
  482.  
  483. /*
  484.  * Special character.
  485.  */
  486. #define QUITCHAR '\034' /* ^\ */
  487.  
  488. /*------------------------------------------------------------------------*/
  489. #endif
  490. /*------------------------------------------------------------------------*/
  491.